package com.sdp.right.db.sys_cron.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.right.db.sys_cron.mapper.SysCronMapper;
import com.sdp.right.db.sys_cron.service.ISysCronService;
import com.sdp.right.entity.SysCron;
import com.sdp.right.service.RemoveSystemService;
import com.sdp.right.utils.RightConstants;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2023-10-18
 */
@Service
@DS(value="right")
public class SysCronServiceImpl extends ServiceImpl<SysCronMapper, SysCron> implements ISysCronService,RemoveSystemService {

	@Override
	public List<SysCron> querySysCronBySystemNo(String systemNo) {
		LambdaQueryWrapper<SysCron> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysCron::getSystemNo, systemNo);
		return list(queryWrapper);
	}

	@Override
	public SysCron querySysCronById(String keyId) {
		LambdaQueryWrapper<SysCron> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysCron::getKeyId, keyId);
		return getOne(queryWrapper,false);
	}

	@Override
	public SysCron querySysCronByClassName(String taskClass) {
		LambdaQueryWrapper<SysCron> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysCron::getTaskClass, taskClass);
		return getOne(queryWrapper,false);
	}

	@Override
	public void removeBySystemNo(String systemNo) {
		LambdaQueryWrapper<SysCron> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysCron::getSystemNo, systemNo);
		remove(queryWrapper);
		
	}

	@Override
	public List<SysCron> querySysCronBySystemNoAndRight(String systemNo) {
		LambdaQueryWrapper<SysCron> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysCron::getSystemNo, systemNo);
		queryWrapper.or().eq(SysCron::getSystemNo, RightConstants.权限模块名.getCode());
		return list(queryWrapper);
	}

}
